export default class Snake{
    head:HTMLElement;
    bodies:HTMLCollection
    snake:HTMLElement
    constructor(){
        this.head = document.querySelector('#snake > div') as HTMLElement
        this.bodies = (document.getElementById('snake') as HTMLElement).getElementsByTagName('div') 
        this.snake = document.getElementById('snake') as HTMLElement
        console.log(Object.prototype.toString.call(this.bodies))
    }
    get X(){
        return this.head.offsetLeft;
    }
    get Y(){
        return this.head.offsetTop;
    }
    set X(v:number){
        this.head.style.left = v + 'px'
    }
    set Y(v:number){
        this.head.style.top = v + 'px'
    }
    addBodies(){
        this.snake.appendChild(document.createElement('div'))
    }
    moveBodies(){
        for(let i = this.bodies.length - 1;i > 0;i --){
            (this.bodies[i] as HTMLElement).style.left = (this.bodies[i-1] as HTMLElement).offsetLeft + 'px';
            (this.bodies[i] as HTMLElement).style.top = (this.bodies[i-1] as HTMLElement).offsetTop + 'px';
        }
    }
}